package com.bjdd.jdy.ui.order;

import com.bjdd.jdy.util.JumpUtil;
import com.bjdd.jdy.util.SpUtil;
import com.bjdd.jdy.util.T;

/**
 * Created by Administrator on 2017/5/12.
 */

public class OrderPresenter extends OrderContract.Presenter {
    @Override
    public void onStart() {
        if (SpUtil.getUser() == null || SpUtil.getUser().equals("") || SpUtil.getUser().getCarrierId() == null) {
            JumpUtil.toLogin(context);
            return;
        }
    }

    @Override
    void getOrders(int page, int size) {
        showLoadingDialog(false);
        String token = SpUtil.getToken();
        String carrierId = SpUtil.getUser().getCarrierId();
        rxManager.add(model.orders(token,carrierId,page,size)
        .subscribe(result -> {
            hideLoadingDialog();
            if (!result.isError()){
                view.orderSuccess(result.getData());
            }else {
                T.show(result.getMsg());
            }
        },e -> {
            hideLoadingDialog();
            T.show("获取失败");
        }));
    }
}
